from ninja import ModelSchema
from core.models import Restaurant, Rating, Sale, User
from ninja.schema import Field


class UserSchema(ModelSchema):
    class Meta:
        model = User
        fields = ['id', 'username']


class RatingSchema(ModelSchema):
    user: UserSchema

    class Meta:
        model = Rating
        fields = ['id', 'user', 'rating']


class SaleSchema(ModelSchema):
    class Meta:
        model = Sale
        fields = '__all__'


class RestaurantSchema(ModelSchema):
    ratings: list[RatingSchema]
    sales: list[SaleSchema]
    total_rating: int | None

    class Meta:
        model = Restaurant
        fields = '__all__'


class RestaurantSimpleSchema(ModelSchema):

    class Meta:
        model = Restaurant
        fields = '__all__'
